#include "atomic_0828_image_acquisition_service.h"

int getImageAcquisition(ImageAcquisitionInput *input, ImageAcquisitionOutput *output) {
    // 检查输入输出指针有效性
    if (input == nullptr || output == nullptr) {
        return ATOMIC_SERVICE_ERROR;
    }

    // 初始化随机数生成器
    static std::default_random_engine rng(std::chrono::system_clock::now().time_since_epoch().count());
    std::uniform_int_distribution<int> noise_dist(0, 10); // 噪声等级范围0-10

    // 填充输出参数
    output->img_width = input->resolution_width;
    output->img_height = input->resolution_height;
    output->pixel_count = output->img_width * output->img_height;

    // 假设每个像素3字节(RGB格式)
    output->data_size = output->pixel_count * 3.0;
    output->actual_format = "RGB888";

    // 获取当前时间戳(秒级)
    auto now = std::chrono::system_clock::now();
    output->timestamp = std::chrono::duration<double>(now.time_since_epoch()).count();

    // 根据采集模式设置帧数
    if (input->capture_mode == 0) { // 单帧采集
        output->frame_count = 1;
    } else if (input->capture_mode == 1) { // 连续采集
        // 简单模拟已采集5帧
        output->frame_count = 5;
    } else {
        // 无效的采集模式
        output->return_type = ATOMIC_SERVICE_NOT_SUPPORT;
        return output->return_type;
    }

    // 随机生成噪声等级
    output->noise_level = noise_dist(rng);

    // 设置成功状态
    output->return_type = ATOMIC_SERVICE_SUCCESS;
    return output->return_type;
}